#include<iostream>
#include<omp.h>
#include<stdio.h>
#include<cstdlib>
#include<sys/time.h>
using namespace std;

int main()
{
  // Partial OpenMP Code for computation of Pi by integration -- v2
  int NSTEPS=10000;
  float step = 1.0 / NSTEPS, x, pi = 0.0; 
  timeval tim;
  gettimeofday(&tim, NULL);
  double t1=tim.tv_sec+(tim.tv_usec/1000000.0);	 
#pragma omp parallel for private(x) reduction(+:pi) 
  for(int i=0; i<NSTEPS;i++){
    x = step * (float(i) - 0.5);
    pi += 4.0 / (1.0 + x * x);
  }
  pi *= step;
  gettimeofday(&tim, NULL);
  double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
  printf("%.6lf seconds elapsed\n", t2-t1);
  std::cout<<pi<<endl;
  return 0;
}
